Imports Microsoft.VisualBasic
Imports System.ComponentModel
Imports System.Collections.Generic

Namespace My
    Public Class MyFormView
        Inherits FormView

        <TypeConverter(GetType(StringArrayConverter)), DefaultValue(GetType(String), Nothing)> _
    Public Property DataNames() As String()
            Get
                If ViewState("DataNames") Is Nothing Then
                    ViewState("DataNames") = New String() {}
                End If

                Return ViewState("DataNames")
            End Get
            Set(ByVal value As String())
                ViewState("DataNames") = value.Clone()

            End Set
        End Property

        <Browsable(False)> _
        Public Property Data() As Dictionary(Of String, Object)
            Get
                If ViewState("Data") Is Nothing Then
                    ViewState("Data") = New Dictionary(Of String, Object)
                End If

                Return ViewState("Data")
            End Get
            Set(ByVal value As Dictionary(Of String, Object))
                ViewState("Data") = value
            End Set
        End Property

        Protected Overrides Sub PerformDataBinding(ByVal data As System.Collections.IEnumerable)
            Me.Data.Clear()

            MyBase.PerformDataBinding(data)
        End Sub

        Protected Overrides Sub OnDataBound(ByVal e As System.EventArgs)

            For Each dataName As String In Me.DataNames
                Me.Data.Add(dataName, DataBinder.Eval(Me.DataItem, dataName))
            Next

            MyBase.OnDataBound(e)
        End Sub

        Public Function FindDDLControl(ByVal id As String) As DropDownList
            Return TryCast(Me.FindControl(id), DropDownList)
        End Function

        Public Function FindTxtControl(ByVal id As String) As TextBox
            Return TryCast(Me.FindControl(id), TextBox)
        End Function

        Public Function FindCalendarTxtControl(ByVal id As String) As MyCalendarTextBoxBase
            Return TryCast(Me.FindControl(id), MyCalendarTextBoxBase)
        End Function

        Public Function FindlblControl(ByVal id As String) As Label
            Return TryCast(Me.FindControl(id), Label)
        End Function

        Public Function FindRblControl(ByVal id As String) As RadioButtonList
            Return TryCast(Me.FindControl(id), RadioButtonList)
        End Function

        Public Function FindBtnControl(ByVal id As String) As Button
            Return TryCast(Me.FindControl(id), Button)
        End Function

    End Class
End Namespace
